<template>
  <div class="exam">
    <el-table :data="pagination">
      <el-table-column prop="adminId" label="面试官">
        <template slot-scope="scope">
          {{filterAdminName(scope.row.adminId)}}
        </template>
      </el-table-column>
      <el-table-column prop="studentId" label="面试人">
        <template slot-scope="scope">
          {{filterStuName(scope.row.studentId)}}
        </template>
        
      </el-table-column>
      <el-table-column prop="date" label="面试日期"></el-table-column>
      <el-table-column prop="status" label="面试状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status == 0 ? 'primary' : 'success'" disable-transitions>{{ scope.row.status == 1 ?
              '已完成' : '已填加'
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remasks" label="面试评价">
        <template slot-scope="scope"> {{ scope.row.remasks ? scope.row.remasks : '暂无' }} </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="pagination.current" :page-sizes="[4, 8, 10, 20]" :page-size="pagination.size"
      layout="total, sizes, prev, pager, next, jumper" :total="pagination.total" class="page">
    </el-pagination>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
export default {
  data() {
    return {
      form: {}, //保存点击以后当前试卷的信息
      pagination:  [],
      stuPagination: [],
      adminPagination: []
    }
  },
  created() {
    this.getInterviewInfo()
    this.getStudent()
    this.getAdmin()
    
  },
  mounted() {
  },
  methods: {
    filterStuName(id) {
      console.log(id);
      const res = this.stuPagination.filter(item => item.studentId == id)
      console.log(res);
      return res[0].studentName
    },
    filterAdminName(id) {
      const res = this.adminPagination.filter(item => item.adminId == id)
      console.log(res);
      return res[0].adminName
    },
    getInterviewInfo() { //分页查询所有面试信息
      this.$axios(`/api/interview/`).then(res => {
        this.pagination = res.data.data
        console.log(this.pagination);
      }).catch(error => {
      })
    },
    getStudent() {
      this.$axios(`/api/students/1/20`).then(res => {
        this.stuPagination = res.data.data.records;
        console.log(this.stuPagination);
      }).catch(error => { });
    },
    getAdmin() {
      this.$axios('/api/admins').then(res => {
        this.adminPagination = res.data.data;
        console.log(this.adminPagination);
      }).catch(error => { });

    },
    //改变当前记录条数
    handleSizeChange(val) {
      this.pagination.size = val
      this.getExamInfo()
    },
    //改变当前页码，重新发送请求
    handleCurrentChange(val) {
      this.pagination.current = val
      this.getExamInfo()
    },
  },
};
</script>

<style lang="scss" scoped>
.exam {
  padding: 0px 40px;

  .page {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .edit {
    margin-left: 20px;
  }
}
</style>